package com.ryhx.ssm.utils;

import com.alibaba.fastjson.JSON;

public final class JsonUtil {

	/**
	 * 
	 * @param object
	 * @return Exception -> null
	 */
	public static String toJSONString(Object object) {
		try {
			return JSON.toJSONString(object);
		} catch (Exception e) {
			return null;
		}
	}

	/**
	 * 
	 * @param jsonStr
	 * @param clazz
	 * @return Exception-> null
	 */
	public static <T> T parseObject(String jsonStr, Class<T> clazz) {
		try {
			return JSON.parseObject(jsonStr, clazz);
		} catch (Exception e) {
			return null;
		}
	}
	
	/**
	 * 克隆对象
	 * @param object
	 * @param clazz
	 * @return
	 */
	public static <T> T cloneObject(Object object, Class<T> clazz) {
		try {
			String objectStr = toJSONString(object);
			return parseObject(objectStr, clazz);
		} catch (Exception e) {
			return null;
		}
	}

}
